class Solution(object):
    def elementInNums(self, nums, queries):
        n = len(nums)
        ans = []
        for t, index in queries:
            t = t % (2 * n)
            if t < n:
                m = n - t
                if index < m:
                    ans.append(nums[t + index])
                else:
                    ans.append(-1)
            else:
                m = t - n
                if index < m:
                    ans.append(nums[index])
                else:
                    ans.append(-1)
        return ans

